package com.sql.azarias.ui.fragment.Presenter;

import android.content.Context;

import com.sql.azarias.base.BasePresenter;
import com.sql.azarias.entity.LiveEntity_;
import com.sql.azarias.http.EntityRequest;
import com.sql.azarias.http.Result;
import com.sql.azarias.http.SimpleHttpListener;
import com.sql.azarias.ui.fragment.view.LiveView;
import com.yanzhenjie.nohttp.RequestMethod;
import com.yanzhenjie.nohttp.rest.CacheMode;

/**
 * Created by ShangQiangLong on 2017/2/20.
 */

public class LivePresenter extends BasePresenter<LiveView>{

    public void requestString(Context context){
        String url = "http://live.bilibili.com/AppIndex/home?";
        EntityRequest<LiveEntity_> entityRequest= new EntityRequest(url, RequestMethod.GET,LiveEntity_.class);
        entityRequest.add("_device", "android");
        entityRequest.add("_hwid", "51e96f5f2f54d5f9");
        entityRequest.add("_ulv", "10000");
        entityRequest.add("access_key", "563d6046f06289cbdcb472601ce5a761&appkey");
        entityRequest.add("appkey", "c1b107428d337928&");
        entityRequest.add("build", "410000");
        entityRequest.add("platform", "android");
        entityRequest.add("scale", "xxhdpi");
        entityRequest.add("sign", "fbdcfe141853f7e2c84c4d401f6a8758");
        entityRequest.setCacheMode(CacheMode.REQUEST_NETWORK_FAILED_READ_CACHE);
        request(context,entityRequest, new SimpleHttpListener<LiveEntity_>() {
            @Override
            public void onSucceed(int what, Result<LiveEntity_> t) {
                super.onSucceed(what, t);
                if (t.isSucceed()) {
                    LiveEntity_ entity = t.getResult();
                    mView.setEntityItem(entity);
                }else{
                    mView.showMassage(t.getError());
                }
            }
        });
    }

}
